#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>

#define u32 unsigned int
struct key_inf{
	char name[10];
	u32 value;
	u32 irq;
	u32 trig;
};
struct key_inf key_press;
char get_buf[100];
struct pollfd keys_pollfd[2];


int main()
{
	int fd,ret;
	//fd = open("/dev/drv_key0", O_RDWR|O_NONBLOCK);
	fd = open("/dev/drv_key0", O_RDWR);
	if(fd < 0)
	{
		printf("drv_key0 open err\r\n");
		exit(1);
	}
	keys_pollfd[0].fd = fd;
	keys_pollfd[0].events = POLLIN;

	keys_pollfd[1].fd = 0;
	keys_pollfd[1].events = POLLIN;
	while(1)
	{
		ret = poll(keys_pollfd, 2, -1);
		if(ret < 0)
		{
			printf("poll_err\r\n");
			exit(1);	
		}
		if(keys_pollfd[0].revents&POLLIN)
		{
			read(fd, &key_press, sizeof(key_press));
			printf("app:irq=%d  value=%d\r\n",key_press.irq,key_press.value);
		
		}
		if(keys_pollfd[1].revents&POLLIN)
		{
			fgets(get_buf, sizeof(get_buf), stdin);
			printf("app:get_buf=%s\r\n",get_buf);
		}
		sleep(1);
	}
	close(fd);
}
